// 接口统一化管理
import axios from "axios";
// 引入基础路径
import { baseURL } from "../config";

// 手机号登录页面(注册)

// function getLogin(user) {
//   return new Promise(function(resolve) {
//     axios
//       .get(baseURL + "login/phoneLogin", {
//         params: { user },
//       })
//       .then((result) => {
//         resolve(result);
//       });
//   });
// }

// 用户名密码登录
// function getPassword(user) {
//   return new Promise(function(resolve) {
//     axios
//       .get(baseURL + "login/getPassword", {
//         params: { user },
//       })
//       .then((result) => {
//         console.log(user);
//         resolve(result);
//       });
//   });
// }

// 发送验证码
function CarePhone(phone) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "login/sendPhoneCode?phone=" + phone)
      .then(result => {
        resolve(result.data);
      })
      .then(err => {
        console.log(err);
      });
  });
}

// 退出登录
function userLogOut() {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "login/logout")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 基本信息
function basicInformation() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/getUserInfo")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 我的订单
function userIndent(lid) {
  return new Promise(function(resolve) {
    axios
      .get(`${baseURL}user/app/getOrderInfo/${lid}`)
      .then(res => {
        resolve(res.data);
        // console.log(lid);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 个人账户
function individualAccount() {
  return new Promise(function(resolve) {
    axios
      .get(`${baseURL}user/app/getByuserOrderInfo`)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 我的合同
function userContract() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/getContract")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 我要约车
function ThreeSubjects(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/getYkJl", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 搜索我要约车
function ConfirmDache(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/getYkJlserach", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 约车列表
function stipulatedList(lid) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/getYkJlInfo", {
        drillId: lid
      })
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 是否预约
function userSubscribe(lid) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/selectLogId", {
        logId: JSON.stringify(lid)
      })
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 储存约课记录
function testRecord(lid) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/UpdateYkLog", {
        logId: JSON.stringify(lid)
      })
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 约课记录
function souvenirStore() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/getYkjlInfo")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 约课记录取消
function callOff(lid) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/delYkjl", {
        logId: lid
      })
      .then(res => {
        resolve(res.data);
        // console.log(lid);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 修改手机号
function alterPhone(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/updatePhone", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 修改手机号的验证码
function securityCode(phone) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/sendUsercode?phone=" + phone)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 修改密码
function alterPasswod(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/updatePassword", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 银行卡类型
function BankCard() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/cms/getYhxl")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 绑定银行卡
function GreenCard(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/updateUserInfoYhk", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 评价
function orderInformation(id) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/selectOrderId/" + id)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 提交评价
function referEvaluate(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/InsertJlPl", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 服务中心->服务投诉->投诉建议==初始化教练列表
function ServiceComplaint() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/fwts")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.log(err);
      });
  });
}

// 服务中心->服务投诉->投诉建议选择教练时调的接口
function instructor() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/findDrillList")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 服务中心->服务投诉->投诉建议选择驾校时调的接口
function drivingSchool() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/findSchoolList")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 服务中心->服务投诉->投诉建议提交
function present(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/saveTsjyInfo", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 服务中心->服务投诉->结果查询
function resultsQuery() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/getTsjylist")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 服务中心->服务投诉->结果查询中的取消投诉
function CancelComplain(id) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/delTsjy/" + id)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 服务中心->用户帮助
function troubleShooting(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "app/cms/getPtggList", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 服务中心->管理机构地址&&湘潭体验中心
function Organization() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/cms/getTjzxAndGljglist")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 验证是否报名成功
function DoubleCounting() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/getAppisrz")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 报名 -> 找教练 -> 详情 -> 个人风采
function PersonageShow(id) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/school/bydrilfc/" + id)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 设置
function SettingUp() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/getUser")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 智能约车->车型
function VehicleModel() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/cms/getcx")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 智能约车
function AboutCar(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/getzNyc", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 智能约车 -> 预约
// UpdateYLog
function subscribe(id) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/UpdateYLog", {
        logId: id
      })
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 编辑订单
function RedactOrder() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/selectOrderIdByXf")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 缴费
function payment() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/updatejf")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 查看订单
function OrderForm() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/selectOrderIdByXf")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 编辑中去报名
function EditApply(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/saveOrderandJf", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

function CancellationOrder() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/delOrderandBasic")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 查看订单详情的评价
function QueryCondition(id) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/selectOrderId2/" + id)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 我的收藏
function MyFavorite() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/favorites/index")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 我的页面 -> 考试平均分
function AverageScore() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/topic/getExamCountAndAvg")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 实名认证
function Authentication(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/getAppisrzSf", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 个人中心的消息列表
function MessageList(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/getTslist", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 个人中心 -> 我的账户 -> 充值
function TopUp(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/userzhCz", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 个人中心 -> 我的账户 -> 提现
function WithdrawDeposit(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/userzhTx", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 上传头像
function updateAvater(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "common/txfileupload", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 银行卡验证
function BankCardVerification() {
  return new Promise(function(resolve) {
    axios
      .get(
        "https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&cardNo=6228483448421184571&cardBinCheck=false"
      )
      .then(res => {
        resolve(res);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

export {
  referEvaluate,
  orderInformation,
  CarePhone,
  basicInformation,
  userIndent,
  individualAccount,
  userLogOut,
  userContract,
  ThreeSubjects,
  stipulatedList,
  securityCode,
  userSubscribe,
  testRecord,
  alterPhone,
  souvenirStore,
  ConfirmDache,
  callOff,
  alterPasswod,
  ServiceComplaint,
  instructor,
  drivingSchool,
  present,
  resultsQuery,
  CancelComplain,
  troubleShooting,
  Organization,
  BankCard,
  GreenCard,
  DoubleCounting,
  SettingUp,
  PersonageShow,
  AboutCar,
  VehicleModel,
  subscribe,
  RedactOrder,
  payment,
  OrderForm,
  EditApply,
  CancellationOrder,
  QueryCondition,
  MyFavorite,
  AverageScore,
  Authentication,
  MessageList,
  TopUp,
  WithdrawDeposit,
  updateAvater,
  BankCardVerification
};
